package com.zqxq.common.enums;

public enum CodeEnum {

    FAIL_SYS(-2, "系统异常"),
    FAIL_TOKEN(-1, "登录异常！"),
    SUCCESS(0, "成功！"),
    FAIL(1, "失败！"),
    PARAM_LOST(5, "参数缺失"),
    FAIL_TOKEN_SIGNATURE(10, "签名异常！"),
    USER_LACK(12, "用户信息不完善"),
    FAIL_CREATE_ORDER(17, "创建订单失败"),
    NET_BUSYING(19, "网络异常"),
    UPLOAD_ERROR(21, "文件上传失败"),
    FAIL_10000(10000, "校验不通过！"),
    FAIL_10001(10001, "请求错误"),
    FAIL_10003(10003, "操作异常，请联系管理员！"),
    FAIL_UPDATE_10004(10004, "修改失败！"),
    /** 疑似重复数据 **/
    STATUS_DUBIOUS(10005, "疑似重复数据"),
    /** 没有查询到信息 */
    NO_INFO(10006, "没有查询到信息"),
    NO_USER(10007, "该用户不存在"),
    IS_VISITOR(10008, "您是游客,请登录！"),
    FAIL_100002(10002, "系统异常！"),
    FAIL_100005(10005, "系统异常！"),
    FAIL_100004(100001, "系统异常！"),
    FAIL_100001(100001, "系统异常！"),
    ;
    private int code;
    private String msg;

    // 从int到enum的转换函数
    public static String valueOf(int value) {
        switch (value) {
            case -2:
                return "FAIL_SYS";
            case -1:
                return "FAIL_TOKEN";
            case 0:
                return "SUCCESS";
            case 1:
                return "FAIL";
            case 5:
                return "PARAM_LOST";
            case 10:
                return "FAIL_TOKEN_SIGNATURE";
            case 12:
                return "USER_LACK";
            case 17:
                return "FAIL_CREATE_ORDER";
            case 19:
                return "NET_BUSYING";
            case 21:
                return "UPLOAD_ERROR";
            case 10001:
            return "FAIL_10001";
            case 10003:
            return "FAIL_10003";
            case 10004:
            return "FAIL_UPDATE_10004";
            default:
                return "";
        }
    }
    CodeEnum(int code, String msg){
        this.code = code;
        this.msg = msg;
    }
    public static Boolean isSuccess(int code){

        return SUCCESS.getCode()==code;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
